# 迭代每一个字符

# 使用while 1
with open('basic_11_2.txt') as f:
    char = f.read(1)
    while char:
        print(char)
        char = f.read(1)
print("*" * 20)

# 使用while 2
with open('basic_11_2.txt') as f:
    while True:
        char = f.read(1)
        if not char: break
        print(char)

print("*" * 20)

# 一次一行
with open('basic_11_2.txt') as f:
    while True:
        line = f.readline()
        if not line: break
        line = line.rstrip('\n')
        print(line)

print("*" * 20)

# fileinput 大型文件读取
import fileinput

for line in fileinput.input('basic_11_2.txt'):
    print(line)

print("*" * 20)
# 文件迭代 file是可以迭代的
with open('basic_11_2.txt') as f:
    for line in f:
        print(line)
